package com.ll.service.Impl;

import com.ll.mapper.UserMapper;
import com.ll.pojo.DTO.DeleteRequest;
import com.ll.pojo.DTO.SearchUserDTO;
import com.ll.pojo.DTO.UserDTO;
import com.ll.pojo.DTO.UserLoginDTO;
import com.ll.pojo.entity.User;
import com.ll.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.Collections;
import java.util.Date;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Override
    public User login(UserLoginDTO userLoginDTO) {
        return userMapper.login(userLoginDTO);
    }

    @Override
    public List<User> getUserInfo(SearchUserDTO searchUserDTO) {
        List<User> userInfo = userMapper.getUserInfo(searchUserDTO);
        return userInfo;
    }

    @Override
    public int deleteUser( List<Long> userIds) {
        return userMapper.deleteUser(userIds);
    }

    @Override
    public int addUser(UserDTO userDTO) {
        User user = new User();
        user.setUsername(userDTO.getUsername());
        user.setPassword(userDTO.getPassword());
        user.setPhone(userDTO.getPhone());
        user.setSex(userDTO.getSex());
        user.setMoney(0.0);
        user.setCreateTime(new Date());
        return userMapper.addUser(user);
    }

    @Override
    public int updateUser(UserDTO userDTO) {
        return userMapper.updateUser(userDTO);
    }
}
